package com.yeping;

import com.yeping.domain.entity.Chapter;
import io.swagger.models.auth.In;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.ArrayList;
import java.util.Arrays;


public class ShopeeTest {
    public static void main(String[] args) {
        System.out.println(Arrays.toString(solution(new int[]{2,1,3,4,5},10)));
    }

    public static int[] solution(int[] costs, int coins) {
        // write code here
        int[] temp = new int[costs.length];
        for (int i = 0; i < costs.length; i++){
            temp[i] = costs[i];
        }
        Arrays.sort(temp);
        int i = 0;

        ArrayList<Integer> arrayList = new ArrayList();
        while (coins > 0){
            arrayList.add(temp[i]);
            coins -= temp[i++];
        }
        int[] res = new int[arrayList.size()];
        int in = 0;
        for (int j = 0; j < costs.length; j++){
            if (arrayList.contains(costs[j])){
                res[in++] = costs[j];
            }
        }
        return res;
    }

    /**
     * 第二题
     * @param originStr
     * @return
     */
    public static String ReverseString(String originStr) {
        // write code here
        String[] s = originStr.split(" ");
        String res = "";
        for (int i = 0; i < s.length; i++){
            res += reverse2(s[i]);
            if (i != s.length - 1) res += " ";
        }
        return res;
    }

    private static String reverse2(String s) {
        String res = "";
        for (int i = s.length() - 1; i >= 0; i--){
            res += s.charAt(i);
        }
        return res;
    }
}
